package com.cskaoyan._03api;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/21 15:59
 **/

public class JoinDemo {
    public static void main(String[] args) {
        System.out.println("main start");
        // 创建线程对象
        JoinThread t = new JoinThread();
        // 启动start
        t.start();

        // 使用join
        try {
            t.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // main打印3个数
        for (int i = 0; i < 3; i++) {
            System.out.println(Thread.currentThread().getName() +
                    "----" + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("main end");

    }
}

class JoinThread extends Thread{
    // run

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(getName() + "----" + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
